<template>
  <div class="row">
    <div class="col-4 mb-3" v-for="item in columnList" :key="item.id">
      <div class="card h-100 shadow-sm ">
        <div class="card-body text-center">
          <img :src="item.avatar" class="card-img-top" :alt="item.avatar">
          <h5 class="card-title">{{ item.title }}</h5>
          <p class="card-text">{{ item.description }}</p>
          <a href="#" class="btn btn-primary">进入专栏</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, PropType, computed } from 'vue'

export interface ColumnProps {
  id: number;
  title: string;
  avatar: string;
  description: string;
}

export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      type: Array as PropType<ColumnProps []>,
      required: true
    }
  },
  setup (props) {
    const columnList = computed(() => {
      return props.list.map(item => {
        if (!item.avatar) {
          item.avatar = require('@/assets/default.jpg')
        } else {
          item.avatar = require(`@/assets/${item.avatar}`)
        }
        return item
      })
    })

    return {
      columnList
    }
  }
})

</script>

<style scoped>
</style>
